package org.flexspeedup.blog.commands
{
import mx.rpc.AsyncToken;
import mx.rpc.IResponder;
import mx.rpc.remoting.mxml.RemoteObject;

import org.flexspeedup.blog.types.ServiceType;
import org.swizframework.utils.chain.ChainStepCommand;

/**
 * Fetches the current authenticated user
 */
public class GetCurrentUserNicknameCommand extends ChainStepCommand implements IResponder
{

    //--------------------------------------------------------------------------
    //
    // Constructor
    //
    //--------------------------------------------------------------------------

    /**
     * Creates a new instance of this class.
     */
    public function GetCurrentUserNicknameCommand()
    {
        super();
    }

    //--------------------------------------------------------------------------
    //
    //  Properties
    //
    //--------------------------------------------------------------------------
    
    //----------------------------------
    // services
    //----------------------------------
    [Inject(source="blogService")]
    /**
     * services bean
     */
    public var services:RemoteObject;

    //----------------------------------
    // user
    //----------------------------------
    [Bindable]
    /**
     * The user returned by the service.
     */
    public var user:String;
   
    //--------------------------------------------------------------------------
    //
    //  Overridden Methods - ChainStepCommand
    //
    //--------------------------------------------------------------------------

    override public function execute():void
    {
        var token:AsyncToken = 
            services.getOperation(ServiceType.GET_CURRENT_USER).send();
        token.addResponder(this);
    }

    //--------------------------------------------------------------------------
    //
    //  Methods - IResponder
    //
    //--------------------------------------------------------------------------    

    /**
     * @inheritDoc mx.rpc.IResponder#result
     */
    public function result(data:Object):void
    {
        user = data.result;
    }

    /**
     * @inheritDoc mx.rpc.IResponder#fault
     */
    public function fault(info:Object):void
    {
    
    }
}
}